// components/share-btn/index.js
import api from '../../utils/api'

Component({
    properties: {
        goodsid: {
            type: String,
        },
        pgpscid: {
            type: String,
        },
        showMsg: {
            type: Boolean,
            value: true
        }
    },
    options: {
        addGlobalClass: true
    },
    data: {
        modal: {
            show: false
        },
    },
    methods: {
        handlerShare() {
            const mobile = wx.getStorageSync('mobile') || ''
            if (!mobile) {
                this.setData({
                    'modal.show': true
                })
                return
            } else {
                this.submit()
            }
        },
        bindSuccess() {
            this.setData({
                'modal.show': false
            })
            this.submit()
        },
        // 提交逻辑获取分享数据
        submit() {
            console.log('提交逻辑获取分享数据')
            let data = {
                goodsid: this.data.goodsid,
                userid: wx.getStorageSync('userid')
            }
            api.post('/api/rebatecustom/save', {
                data
            }).then(res => {
                console.log(res)
                this.triggerEvent('share')
                /*if (this.data.pgpscid === data.userid) {
                    this.triggerEvent('share')
                } else {
                    wx.navigateTo({
                        url: `/pages/detail/detail?id=${data.goodsid}&pgpscid=${data.userid}&userid=${data.userid}&modaltype=rebate`
                    })
                }*/
            }).catch(e => {
                console.log(e)
            })
        }
    }
})
